package com.example.interview.no0103.solution;

import com.example.interview.no0103.Solution;

/**
 * @Description 解答-URL化
 * @ClassName ArraySolution
 * @Author Administrator
 * @Date 2020/7/7 19:36
 * @Version 1.0.0
 */
public class CharArraySolution implements Solution {

    @Override
    public String replaceSpaces(String s, int length) {
        char[] cs = new char[length * 3];
        int i = 0, j = 0;
        char c;
        while(i < length){
            c = s.charAt(i);
            if(c == ' '){
                cs[j++] = '%';
                cs[j++] = '2';
                cs[j++] = '0';
            } else {
                cs[j++] = c;
            }
            i++;
        }
        return new String(cs, 0, j);
    }
}
